package com.info.zhiduoduo.repository.mapper.company;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.entity.company.CompanyPayment;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author tianyonghong
 */
public interface CompanyPaymentMapper extends BaseMapper<CompanyPayment> {

    // 一个企业+一个支付方式只有一条数据
    @Select(" select pay.*,p.pay_type_sn,p.pay_name,p.pay_name_alias,p.source_id,p.source_table " +
            " from zdd_company_payment pay" +
            " left join zdd_payment p on pay.pay_id = p.id " +
            " where pay.compid = #{compid} " +
            " and pay.pay_id = #{payId} " +
            " and pay.deleted = 0 ")
    CompanyPayment getCompanyPayment(Integer compid,Integer payId);

    @Select(" select pay.*,p.pay_type_sn,p.pay_name,p.pay_name_alias,p.source_id,p.source_table " +
            " from zdd_company_payment pay" +
            " left join zdd_payment p on pay.pay_id = p.id " +
            " where pay.compid = #{compid} " +
            " and pay.deleted = 0 ")
    List<CompanyPayment> getCompanyPayList(Integer compid);

    @Select(" select SUM(balance) from zdd_company_payment where deleted = 0 ")
    BigDecimal getAllCompanyBalanceSum();

    // 根据企业Id+银行卡支付商户ID查询
    @Select(" select pay.*,p.pay_type_sn,p.pay_name,p.source_id,p.source_table " +
            " from zdd_company_payment pay" +
            " join zdd_payment p on pay.pay_id = p.id " +
            " where pay.compid = #{compid} " +
            " and p.source_table = 1 and p.source_id = #{merchantId} " +
            " and pay.deleted = 0 ")
    CompanyPayment getCompanyMerchant(Integer compid,Integer merchantId);

}
